/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
  CCell, Cell, Table, TableBody, TableRow, Text, TableHead,
} from "customize-easy-ui-component";
import {DirectLink} from "../../../routing/Link";
import {CCellUnit} from "../../common/base";
import {item宏观检验o} from "./editMacr";
import {TailMenRowIspCheck} from "../../contain/rarelyVary";

//全面检验报告附页
export const 全面检验报告附页= ({theme, orc, rep} :{theme: any, orc:any, rep:any}
) => {
  //整张大表：拆解成2半的， 对应的编辑器也分开2了。
  const somepartOf =React.useCallback((part: number) => {
    const tail=part===1? 'Structural#Structural' : 'ShellAppearance#ShellAppearance';
    let oldunit='';     //带单位
    return <DirectLink href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/`+tail}>
      { item宏观检验o.map(([name,conf,adddesc]: any, i:number) => {
        if((part===1 && i>=21) || (part===2 && i<21))  return null;
        if(i>35 && !orc?.[name]?.a)  return null;
        const {t: title, pr: prefix, span,u:unit}=conf;          //从模型提取参数
        oldunit=unit===null? '' : unit? unit:oldunit;
        return <TableRow key={i}>
          <CCell>{i+1}</CCell>
          {prefix && span>0 && <CCell split rowSpan={span??1}>{prefix}</CCell>}
          <CCell colSpan={null===prefix? 2:1}>{adddesc? orc?.[name]?.a??'／' : title}</CCell>
          {oldunit ?  <CCellUnit unit={oldunit}>{orc?.[name]?.r??'／'}</CCellUnit>
                :
            <CCell>{orc?.[name]?.r??'／'}</CCell>
          }
          <CCell>{orc?.[name]?.m??'／'}</CCell>
        </TableRow>
      }) }
    </DirectLink>;
  },[rep,orc]);

  return <>
    <div css={{"@media print": {paddingBottom: '4rem', pageBreakInside: 'avoid'}} }>
      <Text id='Structural' variant="h2" css={{textAlign: 'center', marginTop: '1rem',
      }}>移动式压力容器全面检验报告附页</Text>
      <div css={{display: 'flex', justifyContent: 'space-between'}}>
        <Text></Text>
        <Text>报告编号：{rep.isp.no}</Text>
      </div>
    </div>
    <Table fixed={ ["3.5%", "5%", "%",  "20%",  "19%"] } css={{borderCollapse: 'collapse', "@media print": {marginTop: '-4rem'}}} tight  miniw={800}>
      <TableHead>
        <DirectLink href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/ALL`}>
          <TableRow>
            <CCell><Text css={{fontSize:'0.6rem'}}>序号</Text></CCell><CCell colSpan={2}>检 验 项 目</CCell><CCell>检查结果</CCell><CCell>备注</CCell>
          </TableRow>
        </DirectLink>
      </TableHead>
      <TableBody>
        {somepartOf(1)}
        {somepartOf(2)}
      </TableBody>
    </Table>
    <TailMenRowIspCheck orc={orc} rep={rep} href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/ProjectList#ProjectList`}>
      <DirectLink href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/ShellAppearance#ShellAppearance`}>
        <TableRow>
          <Cell colSpan={2}><div css={{
            minHeight: '3rem',whiteSpace:'pre-wrap'
          }}>说明：<br/>{orc.宏观结果}</div></Cell>
        </TableRow>
      </DirectLink>
    </TailMenRowIspCheck>
    <Text css={{fontSize:'0.7rem'}}>注：检验结果栏中，打“√”的 表示无问题或者合格的检验项目，打“×”的表示有问题或者不合格的检验项目，填写“无 此项”的表示实际没有的检验项目，划“—”的表示无法检验的项目。</Text>
  </>;
};

